import asyncio
import time

async def get_request(url):
    print('开始请求url',url)
    await asyncio.sleep(2)
    print('请求完成url',url)
    return "请求完成"
def callback(task):
    print(task.result())

async def main():
    tasks = []
    for url in urls:
        c = get_request(url)
        task = asyncio.create_task(c)
        task.add_done_callback(callback)
        tasks.append(task)
    await asyncio.wait(tasks)
 
if __name__ == '__main__':
    starttime = time.time()
    urls = ['www.baidu.com','www.sina.com','www.taobao.com']
    asyncio.run(main())
    print('总耗时',time.time()-starttime)




